package com.txcb.lib.base.view.weigit;


import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * Created by zhangyuncai on 2018/10/20.
 * 高度==状态栏高度的view
 */
public class StatusHeightView extends View {
    public StatusHeightView(Context context) {
        super(context);
    }

    public StatusHeightView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public StatusHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(getMeasuredWidth(), getStatusHeight(getContext()));
    }

    private int getStatusHeight(Context context) {
        int statusBarHeight1 = -1;
        //获取status_bar_height资源的ID
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            statusBarHeight1 = context.getResources().getDimensionPixelSize(resourceId);
        }
        return statusBarHeight1;
    }

}
